
#include "main.h"
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>

bool snd_enabled;

Mix_Chunk* chunk_tak = 0;

void snd_init()
{
	snd_enabled = false;
	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 512))
	{
		printf("Mix_OpenAudio failed: %s\n", Mix_GetError());
		return;
	}

	chunk_tak = Mix_LoadWAV("data/tak.wav");
	if (!chunk_tak)
	{
		printf("Mix_LoadWAV failed: %s\n", Mix_GetError());
		return;
	}

	Mix_AllocateChannels(32);

	snd_enabled = true;
}

void snd_fini()
{
	if (chunk_tak) Mix_FreeChunk(chunk_tak);

	Mix_CloseAudio();

	snd_enabled = false;
}

void snd_tak()
{
	if (!snd_enabled || !chunk_tak) return;
	int ch = Mix_PlayChannel(-1, chunk_tak, 0);
}

int l_Sound_Tak(lua_State* L)
{
	snd_tak();
	return 0;
}
